package com.example.springmvcdemo2;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
public class RequestController {
    @RequestMapping("/r1")
    public String r1(String name){
        return "收到来自"+name+"的请求";
    }
    @RequestMapping("/r2")
    public String r2(Integer age){
        return "收到来自 age = "+age+" 的请求";
    }
    @RequestMapping("/r3")
    public String r3(int age){
        return "收到来自 age = "+age+" 的请求";
    }
    @RequestMapping("/r4")
    public String r4(String name,Integer age){
        return "收到来自 name"+name+" age = "+age+" 的请求";
    }
    @RequestMapping("/r5")
    public String r5(Student student){
        return student.toString();
    }
    @RequestMapping("/r6")
    public String r6(@RequestParam(value = "name")String userName){
        return "收到来自"+userName+"的请求";
    }
    @RequestMapping("/r7")
    public String r7(@RequestParam(value = "name",required = false)String userName){
        return "收到来自"+userName+"的请求";
    }
    @RequestMapping("/r8")
    //接收数组
    public String r8(String[] arr){
        return Arrays.toString(arr);
    }
    @RequestMapping("/r9")
    //接收集合
    public List<Integer> r9(@RequestParam List<Integer> list){
        return list;
    }
    @RequestMapping("/r10")
    //接收json
    //注意添加注解
    public String r10(@RequestBody Student student){
        return student.toString();
    }
    @RequestMapping("/r11/{name}/{age}")
    //获取url上的参数
    public String r11(@PathVariable("name") String userName,@PathVariable int age){
        return "收到来自 "+userName+" age = "+age+"的请求";
    }
    @RequestMapping("/r12")
    //获取文件
    public String r12(MultipartFile file){
        return "获取到文件"+file.getOriginalFilename();
    }
}
